var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 判断是否有上一页
    ypage:false,
    isloadcomplete:true,

    // 日历显示
    isshowCalendar: false,
    // 显示全部施工日志
    isshowporss: false,
    // 判断瓦工还是其他人身份
    isAll: false,
    // 动画滑动距离
    tabX: 70,
    // 滚动距离
    bigscrooltop: 0,
    // 铺贴决算
    isOrderMask: false,
    // 工期这招层
    isperiod: false,
    // 派单遮罩层
    isfromMask: false,
    // 成功派单遮罩层
    issuccessMask: false,

    // 铺贴面积
    area: "",
    // 单价
    price: "",
    // 金额
    totalAmount: 0,
    // 售后信息遮罩层
    maintainmask: false,
    // 售后成功遮罩层
    ismaintainmask: false,
    // 售后时间
    guaranteeDay: '',
    // 保修次数
    guaranteeNum: '',
    // 判断是否有用户评价
    iscustomerGrade: false,
    // 驳回成功
    issuccessMaskreject: false,

  },
  // 瓦工编辑
  bindgowa() {
    wx.navigateTo({
      url: '/bricklayer/pages/unplonePrice/unplonePrice?projectdestil=' + JSON.stringify(this.data.projectdestil),
    })
  },
  // 跳到评论
  gopinlun(e) {
    if (app.globalData.identity == 5 || app.globalData.identity == 8 || app.globalData.identity == 10) {
      wx.navigateTo({
        url: '/shopowner/pages/construction/construction?orderId=' + this.data.orderId + "&&pinlun=" + JSON.stringify(e.currentTarget.dataset.item)
      })
    } else if (app.globalData.identity == 4) {
      wx.navigateTo({
        url: '/supervisor/pages/construction/construction?orderId=' + this.data.orderId + "&&pinlun=" + JSON.stringify(e.currentTarget.dataset.item)
      })
    }
  },

  // 隐藏驳回成功弹窗
  Hidebohui() {
    wx.setStorageSync('istab', true)
    wx.switchTab({
      url: '/pages/project/project',
    })
  },
  // 驳回订单
  reject() {
    let t = this
    wx.showModal({
      content: '是否要驳回项目',
      confirmColor: "#D6000F",
      success(res) {
        if (res.confirm) {
          t.saveSuperviseRebut()
        } else if (res.cancel) {

        }
      }
    })
  },
  // 34.监理驳回
  saveSuperviseRebut(e) {

    let t = this
    wx.showLoading({
      title: '加载中。。。', //提示的内容
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'saveSuperviseRebut',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        orderId: t.data.orderId,
        token: t.data.token
      },
      success: res => {
        wx.hideLoading();

        if (res.data.result == 0) {
          t.setData({
            issuccessMaskreject: true
          })
        } else {
          wx.showToast({
            title: res.data.message,
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          t.setData({
            token: app.token()
          })
        }







      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
      }
    })






  },
  // 修改订单
  gomodifyOrder(e) {

    if (this.data.identity == 5) {
      let projectOrder = this.data.projectOrder
      projectOrder.orderId = this.data.orderId
      this.setData({
        projectOrder: projectOrder
      })


      wx.navigateTo({
        url: "/shopowner/pages/addpeople/addpeople?todo=modifyOrderer&&orderObj=" + JSON.stringify(this.data.projectOrder),
      })
    }



  },


  // 填写售后信息
  unmaintain() {
    console.log(11)
    this.setData({
      maintainmask: true
    })
  },
  // 保修时间限制
  bindguaranteeDay(e) {

    this.setData({
      guaranteeDay: e.detail.value,

    })
  },

  bindsaveCustomerGuarantee() {
    if (this.data.guaranteeNum == '') {
      wx.showToast({
        title: '请填写保修次数',
        duration: 2500, //持续的时间
        icon: 'none', //图标
      })
      return
    }
    this.saveCustomerGuarantee()
  },
  saveCustomerGuarantee() {
    let t = this
    wx.showLoading({
      title: '加载中。。。', //提示的内容
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'saveCustomerGuarantee',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        orderId: t.data.orderId,
        token: t.data.token,
        guaranteeDay: t.data.guaranteeDay,
        guaranteeNum: t.data.guaranteeNum
      },
      success: res => {
        wx.hideLoading();

        if (res.data.result == 0) {
          t.setData({
            ismaintainmask: true
          })
        } else {
          wx.showToast({
            title: res.data.message,
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          t.setData({
            token: app.token()
          })
        }







      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
      }
    })
  },

  Hidemaintainmask() {
    this.setData({
      ismaintainmask: false
    })
    wx.setStorageSync('istab', true)
    wx.redirectTo({
      url: '/shopowner/pages/guaranteedetail/guaranteedetail?orderId=' + this.data.orderId,
    })
  },
  // 跳转任务详情
  gopeople(e) {
    let type = e.currentTarget.dataset.type
    let people = e.currentTarget.dataset.item
    let id = e.currentTarget.dataset.id
    // console.log(type)
    // return
    if (type == 3 && this.data.todo == 'acceptance') {
      wx.navigateTo({
        url: '/pages/my/personal/personal?type=' + type + '&&people=' + JSON.stringify(people) + '&&userid=' + id + "&&workType=" + e.currentTarget.dataset.worktype + "&&orderId=" + this.data.orderId,
      })
    } else {
      wx.navigateTo({
        url: '/pages/personal/personal?type=' + type + '&&people=' + JSON.stringify(people) + '&&id=' + id,
      })
    }
  },
  // 图片预览
  priview(e) {
    let urls = e.currentTarget.dataset.urls.map(item => this.data.Imageurl + item)
    let current = e.currentTarget.dataset.current
    wx.previewImage({
      urls: urls,
      current: current
    })
  },



  // 时间处理
  mytime(statedate, enddate, whendate) {
    var datse = new Date();
    var year = datse.getFullYear(); //  返回的是年份
    var month = datse.getMonth() + 1; //  返回的月份上个月的月份，记得+1才是当月
    var day = datse.getDate(); //  返回的是几号

    if (statedate != '' && enddate != '') {
      // 开始时间戳
      var statedates = new Date(statedate);
      // 计划结束时间戳
      var enddates = new Date(enddate);


      // 计划时间
      var planTime = Math.ceil((enddates - statedates) / (24 * 1000 * 60 * 60)) + 1

      // 剩余时间
      var remaining = Math.ceil((enddates - datse) / (24 * 1000 * 60 * 60)) + 1
      var overdueTime
      if (remaining < 1) {
        overdueTime = Math.abs(remaining - 1)
      } else {
        overdueTime = 0
      }
    }



    if (whendate != '') {
      // 结束时间戳
      var whendates = new Date(whendate);
      // 所用时间
      var when = Math.ceil((whendates - statedates) / (24 * 1000 * 60 * 60)) + 1

    }
    // month+'月'+day+'日'

    return {
      month: month,
      day: day,
      planTime: statedate != '' && enddate != '' ? planTime : '',
      remaining: statedate != '' && enddate != '' ? remaining : '',
      when: whendate != '' ? when : '',
      overdueTime: overdueTime
    }


  },
  // 项目详情接口
  getOrderDetails() {
    let t = this
    wx.showLoading({
      title: '加载中。。。', //提示的内容
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'getOrderDetails',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        // userId: 1569562832576524288,
        orderId: t.data.orderId,
      },
      success: res => {


        t.setData({
          projectOrder: res.data.projectOrder,
          designList: res.data.designList,
          deliverList: res.data.deliverList,
          buildList: res.data.buildList,
          workList: res.data.workList,
          shopowner: res.data.shopowner,
          supervise: res.data.supervise,
          bricklay: res.data.bricklay,
          designer: res.data.designer,
          adviser: res.data.adviser,
          // bricklayList:res.data.bricklayList,
          mytime: t.mytime(res.data.projectOrder.bricklayBeginDate, res.data.projectOrder.bricklayEndDate, res.data.projectOrder.checkDate),

        })






        // 瓦工结算

        if (t.data.workList.length != 0) {
          let bricklayDetailProofList = []
          t.data.workList.forEach(item => {
            let bricklayDetailProof = item.bricklayDetailProof
            if (bricklayDetailProof != '') {

              bricklayDetailProofList.push(...bricklayDetailProof.split(","))

            }


          })

          this.setData({
            bricklayDetailProofList: [...new Set(bricklayDetailProofList)]
          })

          let one1 = t.data.workList.filter(item => item.workType == 1)
          if (one1.length != 0) {

            one1.forEach(item => {
              if (item.superviseCheckProof != '') {
                let workobj1 = {
                  bricklayTotalSize: item.bricklayTotalSize,
                  bricklayGlueDosage: item.bricklayGlueDosage,
                  superviseCheckProof: item.superviseCheckProof,
                  superviseCheckProof: item.superviseCheckProof,
                  bricklayPlaceProof: item.bricklayPlaceProof,
                  bricklayPanoramaProof: item.bricklayPanoramaProof,
                  bricklaySpecificProof: item.bricklaySpecificProof,
                }
                this.setData({
                  workobj1: workobj1
                })
              }
            })
            if (this.data.workobj1) {
              let workobj1 = this.data.workobj1
              workobj1.zong = one1.reduce((total, currentValue) => total + (currentValue.bricklayPayAmount - 0), 0)
              t.setData({
                workobj1: workobj1,
              })
            }
          }
          let two2 = t.data.workList.filter(item => item.workType == 2)
          if (two2.length != 0) {
            two2.forEach(item => {
              if (item.superviseCheckProof != '') {
                let workobj2 = {
                  bricklayTotalSize: item.bricklayTotalSize,
                  bricklayGlueDosage: item.bricklayGlueDosage,
                  superviseCheckProof: item.superviseCheckProof,
                  superviseCheckProof: item.superviseCheckProof,
                  bricklayPlaceProof: item.bricklayPlaceProof,
                  bricklayPanoramaProof: item.bricklayPanoramaProof,
                  bricklaySpecificProof: item.bricklaySpecificProof,
                }
                this.setData({
                  workobj2: workobj2
                })
              }
            })
            if (this.data.workobj2) {
              let workobj2 = this.data.workobj2
              workobj2.zong = two2.reduce((total, currentValue) => total + (currentValue.bricklayPayAmount - 0), 0)
              t.setData({
                workobj2: workobj2,
              })
            }
          }
          let treen3 = t.data.workList.filter(item => item.workType == 3)
          if (treen3.length != 0) {

            treen3.forEach(item => {
              if (item.superviseCheckProof != '') {
                let workobj3 = {
                  bricklayTotalSize: item.bricklayTotalSize,
                  bricklayGlueDosage: item.bricklayGlueDosage,
                  superviseCheckProof: item.superviseCheckProof,
                  bricklayPlaceProof: item.bricklayPlaceProof,
                  bricklayPanoramaProof: item.bricklayPanoramaProof,
                  bricklaySpecificProof: item.bricklaySpecificProof,
                }
                this.setData({
                  workobj3: workobj3
                })
              }
            })

            if (this.data.workobj3) {
              let workobj3 = this.data.workobj3
              workobj3.zong = treen3.reduce((total, currentValue) => total + (currentValue.bricklayPayAmount - 0), 0)
              t.setData({
                workobj3: workobj3
              })
            }

          }

          t.setData({

            oneList: one1,
            twoList: two2,
            treenList: treen3
          })
        }




        // 万年历

        if (t.data.identity == 4) {
          t.setData({
            starttime: res.data.projectOrder.bricklayBeginDate,
            endtime: res.data.projectOrder.bricklayEndDate,

            sign: [{
                data: res.data.projectOrder.designDate,
                color: '#FFA940',
                text: '设计'
              },
              {
                data: res.data.projectOrder.deliverDate,
                color: '#7CB305',
                text: '配送'
              },
              {
                data: res.data.projectOrder.buildDate,
                color: '#45B1ED',
                text: '施工'
              },


            ],
            // startTime:"2022-11-03",
            // endTime:"2022-12-02",
            startdate: {
              date: res.data.projectOrder.checkDate,
              color: '#D6000F',
              text: '验收'
            },
            yjsign: [{
              data: res.data.projectOrder.bricklayEndDate,
              color: '#D6000F',
              text: '计划完工日期'
            }],

          })
          if (t.data.workList.length != 0) {
            let sign = t.data.sign
            if (t.data.oneList.length != 0) {
              sign.push({
                data: t.data.oneList[0].inCheckDate,
                color: '#AA7942',
                text: '铺贴验收'
              })
            }

            if (t.data.twoList.length != 0) {
              sign.push({
                data: t.data.twoList[0].inCheckDate,
                color: '#506FCC',
                text: '美缝验收'
              })
            }

            if (t.data.treenList.length != 0) {
              sign.push({
                data: t.data.treenList[0].inCheckDate,
                color: '#942192',
                text: '清洁验收'
              })
            }


            t.setData({
              sign: sign
            })
          }
        } else {
          t.setData({
            starttime: res.data.projectOrder.bricklayBeginDate,
            endtime: res.data.projectOrder.bricklayEndDate,

            sign: [{
                data: res.data.projectOrder.designDate,
                color: '#FFA940',
                text: '设计'
              },
              {
                data: res.data.projectOrder.deliverDate,
                color: '#7CB305',
                text: '配送'
              },
              {
                data: res.data.projectOrder.buildDate,
                color: '#45B1ED',
                text: '施工'
              },
            ],
            // startTime:"2022-11-03",
            // endTime:"2022-12-02",
            startdate: {
              date: res.data.projectOrder.checkDate,
              color: '#D6000F',
              text: '完工'
            },
            yjsign: [{
              data: '',
              color: '#D6000F',
              text: '计划完工日期'
            }],

          })
        }


        if (t.data.identity == 6) {
          let workObj = (t.data.workList.filter(item => item.userId == app.globalData.userId))[0]
          t.setData({
            workObj: workObj
          })
        }




        // // 是否显示点击
        // let query = wx.createSelectorQuery();
        // query.select('.contentList').boundingClientRect(rect => {
        //   console.log(rect)
        //   if (rect) {
        //     let height = rect.height;

        //     let contentListHight = Math.floor(app.globalData.width * 550 / 375)
        //     console.log(contentListHight)
        //     if (contentListHight <= height) {
        //       this.setData({
        //         ischuxinan: true
        //       })
        //     } else {
        //       this.setData({
        //         ischuxinan: false
        //       })
        //     }
        //   }
        // }).exec();

        // 判断用户已经评价了
        if (res.data.projectOrder.customerGrade != '') {
          t.setData({
            iscustomerGrade: true,
            // 动画滑动距离
            // tabX: 40,
          })
        } else {
          t.setData({
            iscustomerGrade: false,
            // 动画滑动距离
            // tabX: 70,
          })
        }

        // 每个元素下的距离
        setTimeout(() => {
          let t = this
          wx.createSelectorQuery().select('.siteDetails-two').boundingClientRect(res => {
            t.setData({
              one: t.data.bigscrooltop + res.top - t.data.scrooltop
            })
          }).exec()
          // 1.使用wx.createSelectorQuery()查询到需要滚动到的元素位置
          wx.createSelectorQuery().select('.siteDetails-treen').boundingClientRect(res => {
            t.setData({
              two: t.data.bigscrooltop + res.top - t.data.scrooltop
            })
          }).exec()
          wx.createSelectorQuery().select('.siteDetails-four').boundingClientRect(res => {
            t.setData({
              treen: t.data.bigscrooltop + res.top - t.data.scrooltop
            })
          }).exec()
          wx.createSelectorQuery().select('.siteDetails-five').boundingClientRect(res => {
            t.setData({
              fourt: t.data.bigscrooltop + res.top - t.data.scrooltop
            })
          }).exec()
          wx.hideLoading()
        }, 400)

// 公众号进来判断
        if(t.data.officialAccount){
          if(t.data.todo=='delivery'&&res.data.projectOrder.deliverDate!=''){
            t.setData({
              todo:''
            })
          }
          if(t.data.todo=='checkDate'&&res.data.projectOrder.deliverDate!=''){
            t.setData({
              todo:''
            })
          }
          if(t.data.todo=='finished'&&(res.data.projectOrder.bptBalanceFlag==1&&t.data.identity==5)||(res.data.projectOrder.bricklayPayAmountFlag==1&&t.data.identity==4)){
            t.setData({
              todo:''
            })
          }
          if(t.data.todo=='dispatch'&&res.data.projectOrder.superviseId!=''){
            t.setData({
              todo:''
            })
          }

        }else{
          t.setData({
            isloadcomplete:false
          })
        }


;
      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
      }
    })
  },

  // 岩板砖家派单接口
  saveSuperviseDispatch() {
    let t = this
    wx.showLoading({
      title: '加载中。。。', //提示的内容
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'saveSuperviseDispatch',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        token: t.data.token,
        orderId: t.data.orderId,
        planBricklayId: t.data.Bricklayer.id,
        bricklayBudgetSize: t.data.area,
        bricklayUnitPrice: t.data.price,
        bricklayBudgetAmount: t.data.totalAmount,
        bricklayBeginDate: t.data.stateTime,
        bricklayEndDate: t.data.endTime,
      },
      success: res => {
        wx.hideLoading();
        console.log(res)
        if (res.data.result != -1) {
          this.setData({
            isfromMask: false,
            issuccessMask: true
          })
        } else {
          wx.showToast({
            title: res.data.message,
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          t.setData({
            token: app.token()
          })
        }




      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
      }
    })
  },
  // 隐藏遮罩层
  hideOrderMask() {
    this.setData({
      isOrderMask: false
    })
  },


  // 铺贴面积
  bindarea() {
    if (this.data.area == '') {
      return
    }
    let price = this.data.price
    if (price == '') {
      this.setData({
        totalAmount: 0
      })
    } else {
      price = price - 0
      let totalAmount = this.data.area * price.toFixed(2)
      this.setData({
        totalAmount: totalAmount.toFixed(2)
      })
    }

  },



  // 单价

  bindprice() {
    if (this.data.price == '') {
      return
    }
    let price = this.data.price - 0
    let area = this.data.area
    this.setData({
      price: price.toFixed(2),

    })
    console.log(111)
    if (area == '') {
      this.setData({
        totalAmount: 0
      })
    } else {
      area = area - 0
      let totalAmount = this.data.area * price.toFixed(2)
      console.log(totalAmount)
      this.setData({
        totalAmount: totalAmount.toFixed(2)
      })
    }
  },

  // 定金失去焦点
  binddigit() {
    if (this.data.deposit == '') {
      this.setData({
        payment: 0
      })
      return
    }
    let deposit = this.data.deposit - 0
    let price = this.data.price
    this.setData({
      deposit: deposit.toFixed(2),

    })
    if (price == '') {
      this.setData({
        payment: 0
      })
    } else {
      price = price - 0
      let payment = price.toFixed(2) - this.data.deposit

      if (payment < 0) {
        payment = 0
      }
      this.setData({
        payment: payment.toFixed(2)
      })
    }
  },
  // 隐藏支付瓦工金额遮罩层
  HidesuccessMask() {
    this.setData({
      issuccessMask: false
    })
    app.globalData.tabindex = 1
    wx.setStorageSync('istab', true)
    wx.switchTab({
      url: '/pages/project/project',
    })
  },
  // 隐藏开工日期遮罩层
  hideperiodMask() {
    this.setData({
      isperiod: false
    })
  },
  // 隐藏预览派单遮罩层
  hidefromMask() {
    this.setData({
      isfromMask: false
    })
  },
  // 开工录取
  bindDateChangeState(e) {
    console.log(e)
    this.setData({
      stateTime: e.detail.value,
      endTime: e.detail.value,
    })
  },
  // 结束施工日期
  bindDateChangeEnd(e) {
    this.setData({
      endTime: e.detail.value
    })
  },
  // 成功派单
  HidedispatcCar() {
    this.setData({
      issuccessMask: false,
      todo: ''
    })
    wx.setStorageSync('istab', true)
    this.getOrderDetails()
  },


  fakeCallback() {},
  fakeCallbacks() {},


  // 上传施工图片
  unplonepicture() {
    wx.navigateTo({
      url: '/bricklayer/pages/unplonePrice/unplonePrice',
    })
  },
  // 输入单价下一步
  nextPay() {

    if (this.data.area == '') {
      wx.showToast({
        title: '请填写铺贴面积',
        duration: 2500, //持续的时间
        icon: 'none', //图标
      })
      return
    }
    if (this.data.price == '') {
      wx.showToast({
        title: '请填写单价',
        duration: 2500, //持续的时间
        icon: 'none', //图标
      })
      return
    }

    this.setData({
      isOrderMask: false,
      isperiod: true
    })
  },
  // 确认派单
  bindSubmit() {

    this.saveSuperviseDispatch()
  },




  // 开工日期下一步
  nextorder() {

    this.setData({
      isperiod: false,
      isfromMask: true
    })
  },
  // 下一步
  next() {

    if (this.data.projectOrder.planBricklayDate && new Date().getTime() - this.data.projectOrder.planBricklayDate < 24 * 60 * 60 * 1000) {
      wx.showModal({
        content: '该项目您已派遣,若要重新派遣,请再24小时候再重新派遣',
        showCancel: false
      })
      return
    }



    if (this.data.todo == 'distribute') {
      this.setData({
        isOrderMask: true
      })
    } else if (this.data.todo == 'dispatch') {

      wx.navigateTo({
        url: '/supervisor/pages/dispatchPage/dispatchPage?orderId=' + this.data.orderId + "&&designList=" + JSON.stringify(this.data.designList),
      })
    }
  },
  nextesa() {
    wx.navigateTo({
      url: '/supervisor/pages/dispatchPage/dispatchPage?orderId=' + this.data.orderId + "&&designList=" + JSON.stringify(this.data.designList) + "&&Bricklayer=" + JSON.stringify(this.data.Bricklayer),
    })
  },


  // 跳转到待派单页面
  godispatch() {
    let userIdList = this.data.workList.map(item => item.userId)
    // bricklayBeginDate bricklayEndDate
    wx.navigateTo({
      url: '/supervisor/pages/dispatchPage/dispatchPage?orderId=' + this.data.orderId + "&&designList=" + JSON.stringify(this.data.designList) + "&&zhuabpai=" + "zhuabpai" + "&&userIdList=" + JSON.stringify(userIdList) + "&&bricklayBeginDate=" + this.data.projectOrder.bricklayBeginDate + "&&bricklayEndDate=" + this.data.projectOrder.bricklayEndDate + "&&bricklayDetailProof",
    })
  },



  // 内验收
  bindacceptance(e) {
    wx.navigateTo({
      url: '/supervisor/pages/Inneracceptance/Inneracceptance?todo=' + this.data.todo + "&&orderId=" + this.data.orderId + "&&workList=" + JSON.stringify(this.data.workList),
    })

  },
  // 尾款收款凭证或者付给瓦工
  bindmakeCollections() {
    if (this.data.identity == 4) {
      wx.navigateTo({
        url: '/supervisor/pages/collections/collections?todo=' + this.data.todo + "&&projectOrder=" + JSON.stringify(this.data.projectOrder) + "&&orderId=" + this.data.orderId,
      })
    } else if (this.data.identity == 5 || this.data.identity == 10) {
      wx.navigateTo({
        url: '/shopowner/pages/collections/collections?todo=' + this.data.todo + "&&projectOrder=" + JSON.stringify(this.data.projectOrder) + "&&orderId=" + this.data.orderId,
      })
    }
  },



  // 点击tab
  bindTab(e) {








    if (e.currentTarget.dataset.index == 0) {
      // this.setData({
      //   tabX: 70
      // })
      // 1.使用wx.createSelectorQuery()查询到需要滚动到的元素位置
      wx.createSelectorQuery().select('.siteDetails-two').boundingClientRect(res => {

        // 到这里，我们可以从res中读到class为bb4的top，即离顶部的距离（px）
        // 2使用wx.pageScrollTo()将页面滚动到对应位置

        wx.pageScrollTo({
          scrollTop: this.data.bigscrooltop + res.top - this.data.scrooltop * 2 + 24, // 滚动到的位置（距离顶部 px）
          duration: 300 //滚动所需时间 如果不需要滚动过渡动画，设为0（ms）
        })
      }).exec()
    } else if (e.currentTarget.dataset.index == 1) {
      // this.setData({
      //   // tabX:248
      //   tabX: 260
      // })
      // 1.使用wx.createSelectorQuery()查询到需要滚动到的元素位置
      wx.createSelectorQuery().select('.siteDetails-treen').boundingClientRect(res => {

        // 到这里，我们可以从res中读到class为bb4的top，即离顶部的距离（px）
        // 2使用wx.pageScrollTo()将页面滚动到对应位置
        wx.pageScrollTo({
          scrollTop: this.data.bigscrooltop + res.top - this.data.scrooltop * 2 + 24, // 滚动到的位置（距离顶部 px）
          duration: 300 //滚动所需时间 如果不需要滚动过渡动画，设为0（ms）
        })
      }).exec()
    } else if (e.currentTarget.dataset.index == 2) {
      // this.setData({
      //   tabX: 440

      // })
      // 1.使用wx.createSelectorQuery()查询到需要滚动到的元素位置
      wx.createSelectorQuery().select('.siteDetails-four').boundingClientRect(res => {
        // 到这里，我们可以从res中读到class为bb4的top，即离顶部的距离（px）
        // 2使用wx.pageScrollTo()将页面滚动到对应位置
        wx.pageScrollTo({
          scrollTop: this.data.bigscrooltop + res.top - this.data.scrooltop * 2 + 24, // 滚动到的位置（距离顶部 px）
          duration: 300 //滚动所需时间 如果不需要滚动过渡动画，设为0（ms）
        })
      }).exec()
    } else if (e.currentTarget.dataset.index == 3) {
      // this.setData({
      //   tabX: 630
      //   // tabX:598
      // })
      wx.createSelectorQuery().select('.siteDetails-five').boundingClientRect(res => {

        // 到这里，我们可以从res中读到class为bb4的top，即离顶部的距离（px）
        // 2使用wx.pageScrollTo()将页面滚动到对应位置
        wx.pageScrollTo({
          scrollTop: this.data.bigscrooltop + res.top - this.data.scrooltop * 2 + 24, // 滚动到的位置（距离顶部 px）
          duration: 300 //滚动所需时间 如果不需要滚动过渡动画，设为0（ms）
        })
      }).exec()
    }


    //  if(this.data.iscustomerGrade){
    //   if (e.currentTarget.dataset.index == 0) {
    //     this.setData({
    //       tabX: 40
    //     })
    //     // 1.使用wx.createSelectorQuery()查询到需要滚动到的元素位置
    //     wx.createSelectorQuery().select('.siteDetails-two').boundingClientRect(res => {
    //       // console.log(this.data.bigscrooltop+res.top-128-52-70-64)
    //       // 到这里，我们可以从res中读到class为bb4的top，即离顶部的距离（px）
    //       // 2使用wx.pageScrollTo()将页面滚动到对应位置

    //       wx.pageScrollTo({
    //         scrollTop: this.data.bigscrooltop + res.top - this.data.scrooltop * 2 + 24, // 滚动到的位置（距离顶部 px）
    //         duration: 300 //滚动所需时间 如果不需要滚动过渡动画，设为0（ms）
    //       })
    //     }).exec()
    //   } else if (e.currentTarget.dataset.index == 1) {
    //     this.setData({
    //       // tabX:248
    //       tabX: 195
    //     })
    //     // 1.使用wx.createSelectorQuery()查询到需要滚动到的元素位置
    //     wx.createSelectorQuery().select('.siteDetails-treen').boundingClientRect(res => {

    //       // 到这里，我们可以从res中读到class为bb4的top，即离顶部的距离（px）
    //       // 2使用wx.pageScrollTo()将页面滚动到对应位置
    //       wx.pageScrollTo({
    //         scrollTop: this.data.bigscrooltop + res.top - this.data.scrooltop * 2 + 24, // 滚动到的位置（距离顶部 px）
    //         duration: 300 //滚动所需时间 如果不需要滚动过渡动画，设为0（ms）
    //       })
    //     }).exec()
    //   } else if (e.currentTarget.dataset.index == 2) {
    //     this.setData({
    //       tabX: 341

    //     })
    //     // 1.使用wx.createSelectorQuery()查询到需要滚动到的元素位置
    //     wx.createSelectorQuery().select('.siteDetails-four').boundingClientRect(res => {
    //       // 到这里，我们可以从res中读到class为bb4的top，即离顶部的距离（px）
    //       // 2使用wx.pageScrollTo()将页面滚动到对应位置
    //       wx.pageScrollTo({
    //         scrollTop: this.data.bigscrooltop + res.top - this.data.scrooltop * 2 + 24, // 滚动到的位置（距离顶部 px）
    //         duration: 300 //滚动所需时间 如果不需要滚动过渡动画，设为0（ms）
    //       })
    //     }).exec()
    //   } else if (e.currentTarget.dataset.index == 3) {
    //     this.setData({
    //       tabX: 500
    //       // tabX:598
    //     })
    //     wx.createSelectorQuery().select('.siteDetails-five').boundingClientRect(res => {

    //       // 到这里，我们可以从res中读到class为bb4的top，即离顶部的距离（px）
    //       // 2使用wx.pageScrollTo()将页面滚动到对应位置
    //       wx.pageScrollTo({
    //         scrollTop: this.data.bigscrooltop + res.top - this.data.scrooltop * 2 + 24, // 滚动到的位置（距离顶部 px）
    //         duration: 300 //滚动所需时间 如果不需要滚动过渡动画，设为0（ms）
    //       })
    //     }).exec()
    //   }else if(e.currentTarget.dataset.index == 4){
    //     this.setData({
    //       tabX: 650
    //       // tabX:598
    //     })
    //     wx.createSelectorQuery().select('.siteDetails-six').boundingClientRect(res => {

    //       // 到这里，我们可以从res中读到class为bb4的top，即离顶部的距离（px）
    //       // 2使用wx.pageScrollTo()将页面滚动到对应位置
    //       wx.pageScrollTo({
    //         scrollTop: this.data.bigscrooltop + res.top - this.data.scrooltop * 2 + 24, // 滚动到的位置（距离顶部 px）
    //         duration: 650 //滚动所需时间 如果不需要滚动过渡动画，设为0（ms）
    //       })
    //     }).exec()
    //   }
    //  }else{





    //  }

  },







  bindeShowCalender() {
    this.setData({
      isshowCalendar: true
    })
    let calendar = this.selectComponent('#calendar');
    calendar.Rendering();

  },
  bindeHideCalender() {
    this.setData({
      isshowCalendar: false
    })
  },
  bindeShowporss() {
    this.setData({
      isshowporss: true
    })
  },
  bindeHideporss() {
    this.setData({
      isshowporss: false
    })
  },
  bindshowAll() {
    this.setData({
      isAll: true
    })
  },
  bindHideAll() {
    this.setData({
      isAll: false
    })
  },

  bindproductMap() {
    wx.navigateTo({
      url: '/shopowner/pages/productMap/productMap?id=' + this.data.orderId,
    })
  },
  binddeliveryList() {
    if (this.data.identity == 5 || this.data.identity == 10) {

      wx.navigateTo({
        url: '/shopowner/pages/deliveryList/deliveryList?orderId=' + this.data.orderId,
      })
    } else if (this.data.identity == 4) {
      wx.navigateTo({
        url: '/supervisor/pages/deliveryList/deliveryList?orderId=' + this.data.orderId,
      })
    }
  },
  // 验收
  bindcheckAcceptance() {
    console.log(this.data.workList.some(item => item.bricklayId == ''))

    if (this.data.workList.some(item => item.inCheckDate == '' && item.bricklayId != '')) {
      wx.showToast({
        title: '有工人监理未内验收',
        icon: 'none',
        duration: 2500
      })
      return
    }
    wx.navigateTo({
      url: '/shopowner/pages/Inneracceptance/Inneracceptance?todo=check&&orderId=' + this.data.orderId,
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

if(!app.globalData.isonLaunch){
  app.wxlogin()
  .then(res=>{
    {
      this.setData({
        scrooltop: app.globalData.maskheight
      })
    
      let date = new Date()
      let mouth = date.getMonth() - 0 + 1 >= 10 ? date.getMonth() - 0 + 1 : "0" + (date.getMonth() - 0 + 1)
      let day = date.getDate() - 0 >= 10 ? date.getDate() : "0" + (date.getDate())
    
      this.setData({
        value: app.globalData.width * 2 * 0.122,
        today: date.getFullYear() + "-" + mouth + "-" + day,
        stateTime: date.getFullYear() + "-" + mouth + "-" + day,
        endTime: date.getFullYear() + "-" + mouth + "-" + day,
        identity: app.globalData.identity,
        orderId: options.orderId,
        Imageurl: app.globalData.Imageurl,
        userId: app.globalData.userId,
        token: app.token(),
        guaranteeDay: date.getFullYear() + "-" + mouth + "-" + day,
      })
      // console.log(this.data.userId)
      if (options.todo) {
        this.setData({
          todo: options.todo
        })
    
        //deposit是从店长的定金凭证进来的,
      }
      this.getOrderDetails()
      if (options.Bricklayer) {
        this.setData({
          Bricklayer: JSON.parse(options.Bricklayer)
        })
      }
    
      if (options.projectdestil) {
        this.setData({
          projectdestil: JSON.parse(options.projectdestil)
        })
      }
    }
  })
}else{
  this.setData({
    scrooltop: app.globalData.maskheight
  })

  let date = new Date()
  let mouth = date.getMonth() - 0 + 1 >= 10 ? date.getMonth() - 0 + 1 : "0" + (date.getMonth() - 0 + 1)
  let day = date.getDate() - 0 >= 10 ? date.getDate() : "0" + (date.getDate())

  this.setData({
    value: app.globalData.width * 2 * 0.122,
    today: date.getFullYear() + "-" + mouth + "-" + day,
    stateTime: date.getFullYear() + "-" + mouth + "-" + day,
    endTime: date.getFullYear() + "-" + mouth + "-" + day,
    identity: app.globalData.identity,
    orderId: options.orderId,
    Imageurl: app.globalData.Imageurl,
    userId: app.globalData.userId,
    token: app.token(),
    guaranteeDay: date.getFullYear() + "-" + mouth + "-" + day,
  })
  // console.log(this.data.userId)
  if (options.todo) {
    this.setData({
      todo: options.todo
    })

    //deposit是从店长的定金凭证进来的,
  }
  this.getOrderDetails()
  if (options.Bricklayer) {
    this.setData({
      Bricklayer: JSON.parse(options.Bricklayer)
    })
  }

  if (options.projectdestil) {
    this.setData({
      projectdestil: JSON.parse(options.projectdestil)
    })
  }
}

if(options.officialAccount){
  this.setData({
    officialAccount:options.officialAccount,
    ypage:true
  })
}




  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    this.setData({
      isshowCalendar: false
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  onPageScroll(e) {
    this.setData({
      bigscrooltop: e.scrollTop
    })






    if (e.scrollTop <= this.data.one) {
      this.setData({
        tabX: 70
      })
    }
    if (e.scrollTop <= this.data.two && e.scrollTop > this.data.one) {
      this.setData({
        tabX: 260
      })
    }
    if (e.scrollTop <= this.data.treen && e.scrollTop > this.data.two) {
      this.setData({
        tabX: 440
      })
    }
    if (e.scrollTop <= this.data.fourt && e.scrollTop > this.data.treen) {
      this.setData({
        tabX: 630
      })
    }






  }
})